package com.zhang.spring.c_prcxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;


import com.zhang.spring.Service.userService;
import com.zhang.spring.Service.userServiceimpl;

public class userPrcxyFactory implements InvocationHandler {
	private userService uss;

	public userService getUserServiceFactory() {
		userService us = (userService) Proxy.newProxyInstance(
				userPrcxyFactory.class.getClassLoader(),
				userServiceimpl.class.getInterfaces(), this);

		return us;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("打开事务");
		Object invoke = method.invoke(uss, args);
		System.out.println("提交事务");
		return invoke;
	}

	
	public userPrcxyFactory(userService us) {
		super();
		this.uss=us;
	}
	public userService getUss() {
		return uss;
	}

	public void setUss(userService uss) {
		this.uss = uss;
	}

}
